package com.irdstudio.bsp.console.api.rest;

import java.util.List;

import com.irdstudio.bsp.console.service.vo.PluginNlsJobConfVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.irdstudio.sdk.beans.core.vo.ResponseData;
import com.irdstudio.sdk.ssm.web.AbstractController;
import com.irdstudio.bsp.console.service.facade.PluginNlsJobConfService;

@RestController
@RequestMapping("/api")
public class PluginNlsJobConfController extends AbstractController {
    
    private static Logger logger = LoggerFactory.getLogger(PluginNlsJobConfController.class);
    
    @Autowired
    @Qualifier("nlsJobConfService")
    private PluginNlsJobConfService pluginNlsJobConfService;
    
    /**
     * 列表数据查询
     * @param page
     * @param size
     * @return
     */
    @RequestMapping(value="/plugin/nls/job/confs/{pluginId}", method=RequestMethod.POST)
    public @ResponseBody ResponseData<List<PluginNlsJobConfVO>> queryPluginNlsJobConfByPluginId(@PathVariable("pluginId") Integer pluginId, PluginNlsJobConfVO inPluginNlsJobConfVo) {
        inPluginNlsJobConfVo.setPluginId(pluginId);
        logger.info("查询JAVA网贷系统作业插件配置的列表数据，入参：" + JSONObject.toJSONString(inPluginNlsJobConfVo));
        List<PluginNlsJobConfVO> outputVo = pluginNlsJobConfService.queryPluginNlsJobConfByConditionByPage(inPluginNlsJobConfVo);
        return getResponseData(outputVo);
    }
    
    /**
     * 列表数据查询
     * @param page
     * @param size
     * @return
     */
    @RequestMapping(value="/plugin/nls/job/confs/{pluginId}/{taskId}", method=RequestMethod.POST)
    public @ResponseBody ResponseData<List<PluginNlsJobConfVO>> queryPluginNlsJobConf4Select(@PathVariable("pluginId") Integer pluginId, @PathVariable("taskId") String taskId) {
        logger.info("选择页面查询JAVA网贷系统作业插件配置的列表数据，入参：pluginId：{}，taskId：{}", pluginId, taskId);
        List<PluginNlsJobConfVO> outputVo = pluginNlsJobConfService.queryPluginNlsJobConf4Select(pluginId, taskId);
        return getResponseData(outputVo);
    }
    
    /**
     * 根据主键查询详情
     * @return
     */
    @RequestMapping(value="/plugin/nls/job/conf/{pluginId}/{jobName}", method=RequestMethod.GET)
    public @ResponseBody ResponseData<PluginNlsJobConfVO> queryPluginNlsJobConfByPk(@PathVariable("pluginId") Integer pluginId, @PathVariable("jobName") String jobName) {
        PluginNlsJobConfVO inVo = new PluginNlsJobConfVO();
        inVo.setPluginId(pluginId);//插件ID
        inVo.setJobName(jobName);//作业标识
        logger.info("根据主键查询JAVA网贷系统作业插件配置的详情，入参：" + JSONObject.toJSONString(inVo));
        PluginNlsJobConfVO outputVo = pluginNlsJobConfService.queryPluginNlsJobConfByPk(inVo);
        return getResponseData(outputVo);
    }
    
    /**
     * 根据主键删除信息
     * @param inPluginNlsJobConfVo
     * @return
     */
    @RequestMapping(value="/plugin/nls/job/conf", method=RequestMethod.DELETE)
    public @ResponseBody ResponseData<Integer> deletePluginNlsJobConfByPk(@RequestBody PluginNlsJobConfVO inPluginNlsJobConfVo) {
        logger.info("根据主键删除JAVA网贷系统作业插件配置信息，入参：" + JSONObject.toJSONString(inPluginNlsJobConfVo));
        int outputVo = pluginNlsJobConfService.deletePluginNlsJobConfByPk(inPluginNlsJobConfVo);
        logger.info("删除JAVA网贷系统作业插件配置影响记录数：" + outputVo);
        return getResponseData(outputVo);
    }
    
    /**
     * 根据主键更新信息
     * @param inPluginNlsJobConfVo
     * @return
     */
    @RequestMapping(value="/plugin/nls/job/conf", method=RequestMethod.PUT)
    public @ResponseBody ResponseData<Integer> updatePluginNlsJobConfByPk(@RequestBody PluginNlsJobConfVO inPluginNlsJobConfVo) {
        logger.info("根据主键更新JAVA网贷系统作业插件配置信息，入参：" + JSONObject.toJSONString(inPluginNlsJobConfVo));
        int outputVo = pluginNlsJobConfService.updatePluginNlsJobConfByPk(inPluginNlsJobConfVo);
        logger.info("更新JAVA网贷系统作业插件配置影响记录数：" + outputVo);
        return getResponseData(outputVo);
    }
    
    /**
     * 新增数据
     * @param inPluginNlsJobConfVo
     * @return
     */
    @RequestMapping(value="/plugin/nls/job/conf", method=RequestMethod.POST)
    public @ResponseBody ResponseData<Integer> insertPluginNlsJobConf(@RequestBody PluginNlsJobConfVO inPluginNlsJobConfVo) {
        logger.info("新增JAVA网贷系统作业插件配置的记录，入参：" + JSONObject.toJSONString(inPluginNlsJobConfVo));
        int outputVo = pluginNlsJobConfService.insertPluginNlsJobConf(inPluginNlsJobConfVo);
        logger.info("新增JAVA网贷系统作业插件配置影响记录数：" + outputVo);
        return getResponseData(outputVo);
    }
}
